

use "Data/Census.dta", clear

keep if year < 2009 & year > 1986
rename ltd_iss_all_other ltd

gen log_capital = log(total_capital_outlays + 1)
gen diff_log_cap = log_capital - l.log_capital

gen log_operating = log(total_current_oper + 1)
gen diff_log_oper = log_operating - l.log_operating

foreach var in diff_log_cap diff_log_oper {
gen `var'_1 = l5.`var'
gen `var'_2 = l4.`var'
gen `var'_3 = l3.`var'
gen `var'_4 = l2.`var'
gen `var'_5 = l1.`var'
gen `var'_7 = f.`var'
gen `var'_8 = f2.`var'
gen `var'_9 = f3.`var'
gen `var'_10 = f4.`var'
gen `var'_11 = f5.`var'
rename `var' `var'_6
}

keep if ltd > 9000 & ltd <= 10000 & l.ltd == 0 & l2.ltd == 0 & l3.ltd == 0 & l4.ltd == 0 & l5.ltd == 0 & f.total_capital_outlays != . & f2.total_capital_outlays != . & f3.total_capital_outlays != . & f4.total_capital_outlays != . & f5.total_capital_outlays != .

reshape long diff_log_cap_ diff_log_oper_, i(id year) j(relyear) 
sort id year relyear
egen idyear = group(id year)
xtset idyear relyear
replace relyear = relyear - 6

collapse (mean) diff_log_cap diff_log_oper , by(relyear)
 
twoway connected diff_log_cap relyear, xtitle("Year Relative to Debt Issue") ytitle("Change in Log Capital Spending") graphregion(color(white)) legend(off) yscale(range(-0.4(.2)0.8)) ylabel(-0.4(.2)0.8)
graph save "Figure 2a", replace

twoway connected diff_log_oper relyear, xtitle("Year Relative to Debt Issue") ytitle("Change in Log Current Operating Spending") graphregion(color(white)) legend(off) yscale(range(-0.4(.2)0.8)) ylabel(-0.4(.2)0.8)
graph save "Figure 2b", replace

